var Touringcar = require("../../../class/admin/touringcar.c");
module.exports = {
    prefix: "/admin/touringcar/",
    /*get:{
    	'list':{
    		 des: {
    		 	name:'getTouringcarList',
    		 	content:'获取房车列表',
    		 	params:[
    		 		{
    		 			key:'page',
    		 			type:'int'
    		 		}
    		 	]
    		 },
    		 method: function* () {
            	var self = this;
            	try {
                    var data = yield new Touringcar(self.request.query,self.session.admin).getlist();
                	self.body = data;
                } catch (e) {
                    self.body = printError(e);
                };
            }
    	}
    },*/
    post: {
        "create": {
            des: {
                name: "createTouringcar",
                content: "创建房车",
                params: [
                	{
                		key:'title',
                		type:'string'
                	},
                	{
                		key:'image',
                		type:'string'
                	},
                	{
                		key:'thumb',
                		type:'string'
                	},
                	{
                		key:'rentprice',
                		type:'string'
                	},
                	{
                		key:'module',
                		type:'string'
                	},
                	{
                		key:'numseats',
                		type:'Int'
                	},
                	{
                		key:'everyyearlong',
                		type:'number'
                	},
                	{
                		key:'years',
                		type:'number'
                	},
                	{
                		key:'carfacility',
                		type:'string'
                	},
                	{
                		key:'other',
                		type:'string'
                	},
                	{
                		key:'content',
                		type:'string|HtmlDocument'
                	}
                ]
            },
            method: function* () {
            	var self = this;
            	try {
                    var data = yield new Touringcar(self.request.body,self.session.admin).save();
                	self.body = data;
                } catch (e) {
                    self.body = printError(e);
                };
            }
        },
        'update':{
	    	 des: {
                name: "updateTouringcar",
                content: "修改房车",
                params: [
                	{
                		key:'_id',
                		type:'string'
                	},
                	{
                		key:'title',
                		type:'string'
                	},
                	{
                		key:'image',
                		type:'string'
                	},
                	{
                		key:'thumb',
                		type:'string'
                	},
                	{
                		key:'rentprice',
                		type:'string'
                	},
                	{
                		key:'module',
                		type:'string'
                	},
                	{
                		key:'numseats',
                		type:'Int'
                	},
                	{
                		key:'everyyearlong',
                		type:'number'
                	},
                	{
                		key:'years',
                		type:'number'
                	},
                	{
                		key:'carfacility',
                		type:'string'
                	},
                	{
                		key:'other',
                		type:'string'
                	},
                	{
                		key:'content',
                		type:'string|HtmlDocument'
                	}
                ]
    		},
            method: function* () {
            	var self = this;
            	try {
                    var receive_data = self.request.body;
	            	if(!receive_data._id){
	            		 printError('房车不存在！');
	            	}
	            	var data = new Touringcar(receive_data,self.session.admin).update();
                	self.body = data;
                } catch (e) {
                    self.body = printError(e);
                };
            }
    	}
    },
    delete:{
    	'delete/:_id':{
    		 des: {
                name: "postDelete",
                content: "删除指定房车",
                params: [
                    {
                        params: "_id",
                        type: "string"
                    }
                ]
            },
            method: function* () {
                var self = this;
                try {
                	var send_data = {'_id':self.params._id};
                   	var data = yield new Touringcar(send_data,self.session.admin).delete(self.params._id);
                    self.body = data;
                    /*if (_post.type !== "error") {
                        yield _Module.upgradepost(_post._module);
                    };*/
                } catch (e) {
                    self.body = printError(e);
                };
            }
    	}
    }
}
